/*
    Project:        Home Power Control
    File:           HPCRequest.cpp
    Author:         christian@karunamusic.at
    Date:           02.2015
    Description:    Requests for the client/server communication.
 */

#include "HPCRequest.h"

HPCRequest::HPCRequest(TRequestType rt)
    : QByteArray(), m_Stream(0), m_Type(rt), m_Request(true)
{
    setup();
}

HPCRequest::HPCRequest( QByteArray& ref )
    : QByteArray(ref), m_Stream(0), m_Type(undefined), m_Request(false)
{
    setup();
}

HPCRequest::~HPCRequest()
{
    if ( m_Stream )
    {
        delete m_Stream;
    }
}

void HPCRequest::setup()
{
    if ( m_Request )
    {
        m_Stream = new QDataStream(this,QIODevice::WriteOnly);
        *m_Stream << (quint8)m_Type;
    }
    else
    {
        m_Stream = new QDataStream(this,QIODevice::ReadOnly);
        quint8 t;
        *m_Stream >> t;
        m_Type = (TRequestType)t;
    }
}
